<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}XBot管理后台{% endblock %}</title>
    
    <!-- 本地CSS文件 -->
    <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/bootstrap-icons.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/animate.min.css') }}" rel="stylesheet">
    
    <style>
        :root {
            --primary-color: #4361ee;
            --primary-light: #4895ef;
            --primary-dark: #3f37c9;
            --secondary-color: #4cc9f0;
            --accent-color: #f72585;
            --text-color: #212529;
            --text-muted: #6c757d;
            --bg-color: #f8f9fa;
            --bg-sidebar: #ffffff;
            --border-radius: 0.75rem;
            --card-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.08);
            --sidebar-width: 240px;
            --sidebar-width-collapsed: 70px;
            --header-height: 60px;
            --transition-speed: 0.3s;
        }
        
        * {
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            margin: 0;
            padding: 0;
            min-height: 100vh;
            transition: margin-left var(--transition-speed);
        }
        
        /* 布局 */
        .layout-wrapper {
            display: flex;
            min-height: 100vh;
            width: 100%;
        }
        
        /* 侧边栏 */
        .sidebar {
            width: var(--sidebar-width);
            min-height: 100vh;
            background-color: var(--bg-sidebar);
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
            z-index: 1030;
            overflow-y: auto;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
            transition: all var(--transition-speed) ease;
        }
        
        .sidebar-collapsed .sidebar {
            width: var(--sidebar-width-collapsed);
        }
        
        .sidebar-brand {
            height: var(--header-height);
            display: flex;
            align-items: center;
            justify-content: flex-start;
            padding: 0 1.5rem;
            color: var(--primary-color);
            font-weight: 700;
            font-size: 1.25rem;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        }
        
        .sidebar-brand i {
            margin-right: 0.75rem;
            font-size: 1.5rem;
            transition: margin var(--transition-speed);
        }
        
        .sidebar-collapsed .sidebar-brand span {
            display: none;
        }
        
        .sidebar-collapsed .sidebar-brand i {
            margin-right: 0;
        }
        
        .sidebar-menu {
            padding: 1rem 0;
        }
        
        .sidebar-header {
            color: var(--text-muted);
            font-size: 0.75rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            padding: 1.5rem 1.5rem 0.5rem;
            transition: opacity var(--transition-speed);
        }
        
        .sidebar-collapsed .sidebar-header {
            opacity: 0;
        }
        
        .sidebar-item {
            position: relative;
            display: block;
            padding: 0.5rem 1.5rem;
            color: var(--text-color);
            text-decoration: none;
            transition: all 0.2s ease;
        }
        
        .sidebar-item:hover {
            color: var(--primary-color);
            background-color: rgba(67, 97, 238, 0.05);
        }
        
        .sidebar-item.active {
            color: var(--primary-color);
            background-color: rgba(67, 97, 238, 0.1);
            font-weight: 500;
        }
        
        .sidebar-item.active::before {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 3px;
            background-color: var(--primary-color);
        }
        
        .sidebar-icon {
            width: 1.5rem;
            text-align: center;
            margin-right: 0.75rem;
            transition: margin var(--transition-speed);
        }
        
        .sidebar-collapsed .sidebar-item span {
            display: none;
        }
        
        .sidebar-collapsed .sidebar-icon {
            margin-right: 0;
            font-size: 1.25rem;
        }
        
        .sidebar-footer {
            padding: 1rem 1.5rem;
            border-top: 1px solid rgba(0, 0, 0, 0.05);
            margin-top: auto;
        }
        
        /* 内容区域 */
        .main-content {
            flex: 1;
            margin-left: var(--sidebar-width);
            transition: margin-left var(--transition-speed);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }
        
        .sidebar-collapsed .main-content {
            margin-left: var(--sidebar-width-collapsed);
        }
        
        /* 顶部导航 */
        .top-navbar {
            height: var(--header-height);
            padding: 0 1.5rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            background-color: #fff;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            position: sticky;
            top: 0;
            z-index: 1020;
        }
        
        .menu-toggle {
            background: none;
            border: none;
            color: var(--text-color);
            font-size: 1.25rem;
            cursor: pointer;
            width: 2rem;
            height: 2rem;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            transition: background-color 0.2s;
        }
        
        .menu-toggle:hover {
            background-color: rgba(0, 0, 0, 0.05);
        }
        
        .top-navbar-right {
            display: flex;
            align-items: center;
        }
        
        .user-dropdown .dropdown-toggle {
            display: flex;
            align-items: center;
            text-decoration: none;
            color: var(--text-color);
            font-weight: 500;
            padding: 0.5rem;
            border-radius: var(--border-radius);
        }
        
        .user-dropdown .dropdown-toggle:hover {
            background-color: rgba(0, 0, 0, 0.05);
        }
        
        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background-color: var(--primary-color);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            margin-right: 0.5rem;
        }
        
        /* 内容容器 */
        .content-container {
            padding: 1.5rem;
            flex: 1;
        }
        
        .page-title {
            margin-bottom: 1.5rem;
            font-weight: 700;
            color: var(--text-color);
            display: flex;
            align-items: center;
        }
        
        .page-title-icon {
            margin-right: 0.75rem;
            font-size: 1.75rem;
            color: var(--primary-color);
        }
        
        /* 卡片样式 */
        .card {
            border: none;
            border-radius: var(--border-radius);
            box-shadow: var(--card-shadow);
            margin-bottom: 1.5rem;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            background: white;
        }
        
        .card:hover {
            transform: translateY(-3px);
            box-shadow: 0 0.75rem 1.5rem rgba(0, 0, 0, 0.12);
        }
        
        .card-header {
            background-color: white;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            padding: 1.25rem 1.5rem;
            font-weight: 600;
            color: var(--text-color);
            border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
        }
        
        .card-header-tabs {
            margin: -0.75rem -1.5rem;
        }
        
        .card-body {
            padding: 1.5rem;
        }
        
        /* 状态指示器 */
        .status-indicator {
            display: inline-block;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-right: 0.5rem;
        }
        
        .status-online {
            background-color: #10b981;
            box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
            animation: pulse 2s infinite;
        }
        
        .status-offline {
            background-color: #ef4444;
        }
        
        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
            }
            70% {
                box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
            }
        }
        
        /* 按钮样式 */
        .btn {
            border-radius: 0.5rem;
            padding: 0.5rem 1rem;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        .btn:hover {
            transform: translateY(-2px);
        }
        
        .btn-primary {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }
        
        .btn-primary:hover, .btn-primary:focus {
            background-color: var(--primary-dark);
            border-color: var(--primary-dark);
            box-shadow: 0 4px 10px rgba(63, 55, 201, 0.3);
        }
        
        /* 面包屑导航 */
        .breadcrumb {
            background-color: transparent;
            padding: 0.5rem 0;
            margin-bottom: 1rem;
        }
        
        .breadcrumb-item a {
            color: var(--text-muted);
            text-decoration: none;
        }
        
        .breadcrumb-item.active {
            color: var(--text-color);
        }
        
        /* 表单控件 */
        .form-control, .form-select {
            border-radius: 0.5rem;
            padding: 0.5rem 1rem;
            border: 1px solid rgba(0, 0, 0, 0.1);
        }
        
        .form-control:focus, .form-select:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.25rem rgba(67, 97, 238, 0.25);
        }
        
        /* 表格样式 */
        .table {
            border-collapse: separate;
            border-spacing: 0;
        }
        
        .table th {
            border-bottom-width: 1px;
            font-weight: 600;
            text-transform: uppercase;
            font-size: 0.75rem;
            letter-spacing: 0.025em;
            color: var(--text-muted);
        }
        
        /* 响应式调整 */
        @media (max-width: 992px) {
            .sidebar {
                transform: translateX(-100%);
            }
            
            .sidebar-shown .sidebar {
                transform: translateX(0);
            }
            
            .main-content {
                margin-left: 0 !important;
            }
            
            .backdrop {
                position: fixed;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                background-color: rgba(0, 0, 0, 0.5);
                z-index: 1025;
            display: none;
        }
        
            .sidebar-shown .backdrop {
            display: block;
        }
        }
    </style>
    
    {% block head %}{% endblock %}
</head>
<body>
    <div class="layout-wrapper" id="layoutWrapper">
        <!-- 移动端遮罩 -->
        <div class="backdrop" id="backdrop" onclick="toggleSidebar()"></div>
    
        <!-- 侧边栏 -->
        <aside class="sidebar" id="sidebar">
            <div class="sidebar-brand">
                <i class="bi bi-robot"></i>
                <span>XBot管理后台</span>
            </div>
            
            <div class="sidebar-menu">
                <div class="sidebar-header">主导航</div>
                
                <a href="/" class="sidebar-item {{ 'active' if request.endpoint == 'index' }}">
                    <i class="bi bi-speedometer2 sidebar-icon"></i>
                    <span>仪表盘</span>
                </a>
                
                <a href="/chat-records" class="sidebar-item {{ 'active' if request.endpoint == 'chat_records' }}">
                    <i class="bi bi-chat-dots sidebar-icon"></i>
                    <span>聊天记录</span>
                </a>
                
                <div class="sidebar-header">好友管理</div>
                
                <a href="/friends" class="sidebar-item {{ 'active' if request.endpoint == 'friends' }}">
                    <i class="bi bi-person sidebar-icon"></i>
                    <span>好友列表</span>
                </a>
                
                <a href="/groups" class="sidebar-item {{ 'active' if request.endpoint == 'groups' }}">
                    <i class="bi bi-people sidebar-icon"></i>
                    <span>群聊管理</span>
                </a>
                
                <div class="sidebar-header">系统设置</div>
                
                <a href="/plugins" class="sidebar-item {{ 'active' if request.endpoint == 'plugins' }}">
                    <i class="bi bi-puzzle sidebar-icon"></i>
                    <span>插件管理</span>
                </a>
                
                <a href="/settings" class="sidebar-item {{ 'active' if request.endpoint == 'settings' }}">
                    <i class="bi bi-gear sidebar-icon"></i>
                    <span>系统设置</span>
                </a>
                
                <a href="/users" class="sidebar-item {{ 'active' if request.endpoint == 'users' }}">
                    <i class="bi bi-person-badge sidebar-icon"></i>
                    <span>用户管理</span>
                </a>
                
                <a href="/logout" class="sidebar-item">
                    <i class="bi bi-box-arrow-left sidebar-icon"></i>
                    <span>退出登录</span>
                </a>
                </div>
        </aside>

            <!-- 主内容区 -->
        <div class="main-content">
            <!-- 顶部导航 -->
            <nav class="top-navbar">
                <div class="d-flex align-items-center">
                    <button class="menu-toggle me-2" id="menuToggle" onclick="toggleSidebar()">
                        <i class="bi bi-list"></i>
                                </button>
                    
                    <!-- 面包屑导航 -->
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb mb-0">
                            <li class="breadcrumb-item"><a href="/">首页</a></li>
                            <li class="breadcrumb-item active" aria-current="page">{{ self.title() }}</li>
                        </ol>
                    </nav>
                    </div>
                    
                <div class="top-navbar-right">
                    <!-- 微信状态 -->
                    <div class="me-4 d-none d-md-block">
                        <span id="wechatStatusText" class="d-flex align-items-center">
                            <span class="status-indicator status-offline"></span>
                            微信未登录
                        </span>
                        </div>

                    <!-- 用户下拉菜单 -->
                    <div class="user-dropdown dropdown">
                        <a class="dropdown-toggle" href="#" role="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                            <div class="user-avatar">
                                {% if current_user.is_authenticated %}
                                    {{ current_user.username[0]|upper }}
                                {% else %}
                                    <i class="bi bi-person"></i>
                                {% endif %}
                            </div>
                            <span class="d-none d-md-inline">
                                {% if current_user.is_authenticated %}
                                    {{ current_user.username }}
                                {% else %}
                                    游客
                                {% endif %}
                            </span>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                            <li><h6 class="dropdown-header">用户菜单</h6></li>
                            <li><a class="dropdown-item" href="/profile"><i class="bi bi-person me-2"></i>个人资料</a></li>
                            <li><a class="dropdown-item" href="/settings"><i class="bi bi-gear me-2"></i>设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="/logout"><i class="bi bi-box-arrow-right me-2"></i>退出登录</a></li>
                        </ul>
                        </div>
                                    </div>
            </nav>
            
            <!-- 主内容容器 -->
            <div class="content-container">
                <!-- 页面标题 -->
                <h2 class="page-title">
                    {% block page_title_icon %}<i class="bi bi-speedometer2 page-title-icon"></i>{% endblock %}
                    {% block page_title %}仪表盘{% endblock %}
                </h2>
                
                <!-- 页面内容 -->
                {% block content %}{% endblock %}
                            </div>
                        </div>
                    </div>
                    
    <!-- JavaScript库 -->
    <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/axios.min.js') }}"></script>
    
    <!-- 自定义脚本 -->
    <script>
        // 侧边栏折叠/展开功能
        function toggleSidebar() {
            const layoutWrapper = document.getElementById('layoutWrapper');
            
            if (window.innerWidth < 992) {
                // 移动端显示/隐藏
                layoutWrapper.classList.toggle('sidebar-shown');
                } else {
                // 桌面端折叠/展开
                layoutWrapper.classList.toggle('sidebar-collapsed');
                
                // 保存用户偏好
                localStorage.setItem('sidebarCollapsed', layoutWrapper.classList.contains('sidebar-collapsed'));
            }
        }
        
        // 页面加载时恢复侧边栏状态
        document.addEventListener('DOMContentLoaded', function() {
            const layoutWrapper = document.getElementById('layoutWrapper');
            
            // 根据屏幕尺寸和用户偏好设置侧边栏状态
            if (window.innerWidth < 992) {
                // 移动端默认隐藏
                layoutWrapper.classList.remove('sidebar-collapsed');
                layoutWrapper.classList.remove('sidebar-shown');
                } else {
                // 桌面端根据用户偏好
                const sidebarCollapsed = localStorage.getItem('sidebarCollapsed') === 'true';
                if (sidebarCollapsed) {
                    layoutWrapper.classList.add('sidebar-collapsed');
            } else {
                    layoutWrapper.classList.remove('sidebar-collapsed');
                }
            }
            
            // 检查微信登录状态
            checkWechatStatus();
        });
        
        // 检查微信登录状态
        function checkWechatStatus() {
                    const statusText = document.getElementById('wechatStatusText');
                    
            fetch('/api/wechat/status')
                .then(response => response.json())
                .then(data => {
                    if (data && data.success && data.data && data.data.is_logged_in) {
                        statusText.innerHTML = '<span class="status-indicator status-online"></span>微信已登录';
                    } else {
                        statusText.innerHTML = '<span class="status-indicator status-offline"></span>微信未登录';
                    }
                })
                .catch(error => {
                    console.error('检查微信状态失败:', error);
                });
        }
    </script>
    
    {% block scripts %}{% endblock %}
</body>
</html> 